﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeddingEventManagement_API
{
    public class SettingsManager : ISettingsManager
    {

        #region ISettingsManager Members

        public List<SiteSetting> GetSettings()
        {
            using (CreativeSystemsEntities db = new CreativeSystemsEntities())
            {
                return db.SiteSettings.ToList();
            }
        }

        public SiteSetting GetSetting(string key)
        {
            using (CreativeSystemsEntities db = new CreativeSystemsEntities())
            {
                return db.SiteSettings.Where(s => s.key == key).Single();
            }
        }

        public void SaveSetting(SiteSetting setting)
        {
            using (CreativeSystemsEntities db = new CreativeSystemsEntities())
            {
                var set = db.SiteSettings.Where(s => s.key == setting.key).Single();
                set.value = setting.value;
                db.SaveChanges();
            }
        }

        #endregion
    }
}
